package com.example.wyc.mybiye1;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.example.wyc.mybiye.R;

public class Ma1Activity {
    //private ViewFlipper vflp_help;
    private Activity mContext;
    private LayoutInflater mInflater;
    private View mCurrentView;

    WebView webView;
    public Ma1Activity(Activity context){
        mContext = context;
        //为之后将Layout转化为view时用
        mInflater = LayoutInflater.from(mContext);
    }
    public void initView(){
        //设置布局文件
        mCurrentView = mInflater.inflate(R.layout.activity_ma1, null);
        //--------
        webView=mCurrentView.findViewById(R.id.web_view);
        webView.setWebViewClient(new WebViewClient() {
            //在webview里打开新链接
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView.getSettings().setJavaScriptEnabled(true);  //设置WebView属性,运行执行js脚本
        webView.loadUrl("https://m.ithome.com/");          //调用loadUrl方法为WebView加入链接
        //--------------
//        vflp_help = (ViewFlipper) mCurrentView.findViewById(R.id.vflp_help);
//        vflp_help.startFlipping();
        mCurrentView.setVisibility(View.VISIBLE);
    }
    /**
     * 获取当前在导航栏上方显示对应的View
     */
    public View getView() {
        if (mCurrentView == null) {
            initView();
        }
        return mCurrentView;
    }
    /**
     * 显示当前导航栏上方所对应的view界面
     */
    public void showView(){
        if(mCurrentView == null){
            initView();
        }
        mCurrentView.setVisibility(View.VISIBLE);
    }
    /**
     * 显示当前导航栏上方所对应的view界面
     */
    public WebView showWeb(){
        return  webView;
    }
}
